package pruebas;

import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class LayoutManager extends VerticalFieldManager {

	private int _backgroundColor;
	private int _rolloverBackgroundColor;

	public LayoutManager(int backgroundColor, int rolloverBackgroundColor) {
		super();
		_backgroundColor = backgroundColor;
		_rolloverBackgroundColor = rolloverBackgroundColor;
	}
	
	public LayoutManager(int backgroundColor, int rolloverBackgroundColor, long style) {
		super(style);
		_backgroundColor = backgroundColor;
		_rolloverBackgroundColor = rolloverBackgroundColor;
	}

	protected void onFocus(int direction) {
		super.onFocus(direction);
		
		int fieldCount = this.getFieldCount();
		if (direction == 1) {
			if (fieldCount > 0) {
				Field firstField = this.getField(0);
				firstField.setFocus();
				
			}
		}

		if (direction == -1) {
			if (fieldCount > 0) {
				Field lastField = this.getField(fieldCount - 1);
				lastField.setFocus();
			}
		}
		invalidate();
	}

	protected void onUnfocus() {
		super.onUnfocus();
		invalidate();
	}

	public void paint(Graphics g) {
		if (this.isFocus()) {
			g.setColor(Color.WHITE);
            g.setBackgroundColor(_rolloverBackgroundColor);
            g.clear();
	    } else {
            g.setBackgroundColor(_backgroundColor);
            g.clear();
	    }
    super.paint(g);
	}
}
